<?php
	session_start();
	if (isset($_GET['callback'])) {
		//get current user
		$email = $_GET['email'];
		$total = $_GET['total'];
		$score = $_SESSION["$email"];
		
		// include db connect class
		require_once __DIR__ . '/db_connect.php';
		// connecting to db
		$db = new DB_CONNECT();
		$sql = "SELECT id FROM user_info WHERE email='$email'";
		$result = mysql_query($sql);
		$data_row = mysql_fetch_array($result);
		$user_id = $data_row[0];
		
		date_default_timezone_set('Asia/Ho_Chi_Minh');
		$time = date('l jS \of F Y h:i:s A');
		
		$sql = "INSERT INTO result_history (user_id, time, result) VALUES ($user_id, '$time', $score)";
		mysql_query($sql);
		
		$cb = $_GET['callback'];
		//make a response array to encode json...
		$response = array();
		$response["success"] = 4;
		$response["message"] = "result";
		$response["email"] = $email;
		$response["score"] = $score;
		echo $cb."(".json_encode($response).");";
	}
?>